 
package com.wtzz.police.base.model.response;

import com.wtzz.police.base.model.enums.WtzzResponse;
import io.swagger.annotations.ApiModel;

import java.util.Optional;

/**  
* 
*  
* @author zxh  
* @date 2019-01-24   
*/
@ApiModel("返回的数据结构")
public class ResponseBean<T> {

	private boolean success;
	private T data;
	private String code;
	private String msg;
	
	
	public static <T> ResponseBean<T> of(Optional<T> t){
		if(t.isPresent())
			return new ResponseBean<>(true,t.get(), WtzzResponse.SUCCESS_OPTION);
		else
			return new ResponseBean<>(true,WtzzResponse.NO_RECORD);
	}
	
	public static <T> ResponseBean<T> of(T t){
		return new ResponseBean<>(true,t,WtzzResponse.SUCCESS_OPTION);
	}
	
	public ResponseBean(){}
	 
	public ResponseBean(boolean success, T data) {
		super();
		this.success = success;
		this.data = data;
	}
	
	public ResponseBean(boolean success, T data, String code, String msg) {
		super();
		this.success = success;
		this.data = data;
		this.code = code;
		this.msg = msg;
	}
 
	public ResponseBean(boolean success, String code, String msg) {
		this.success = success;
		this.code = code;
		this.msg = msg;
	}
	public ResponseBean(boolean success,WtzzResponse enums){
		this.success=success;
		this.code=enums.getCode();
		this.msg=enums.getMsg();
	}
	public ResponseBean(boolean success,T data,WtzzResponse enums){
		this.success=success;
		this.data=data;
		this.code=enums.getCode();
		this.msg=enums.getMsg();
	}
	
	public boolean isSuccess() {
		return success;
	}
	public T getData() {
		return data;
	}
	public String getcode() {
		return code;
	}
	public String getmsg() {
		return msg;
	}
	public void setSuccess(boolean success) {
		this.success = success;
	}
	public void setData(T data) {
		this.data = data;
	}
	public void setcode(String code) {
		this.code = code;
	}
	public void setmsg(String msg) {
		this.msg = msg;
	}

	@Override
	public String toString() {
		return "ResponseBean [success=" + success + ", data=" + data + ", code=" + code + ", msg=" + msg
				+ "]";
	}
	
}